package com.zlx.store.common.util;

import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Objects;


public class StringTool {
    public static boolean isNull(Object... objects) {
        if (objects == null) return true;
        if (Arrays.stream(objects).anyMatch(o -> o instanceof String && o.toString().trim().isEmpty())) return true;
        return Arrays.stream(objects).anyMatch(Objects::isNull);
    }

    public static Boolean isNum(String... str) {
        return Arrays.stream(str).anyMatch(s -> s.matches("^\\d{1,}$"));
    }


    public static boolean isChinaPhoneLegal(String... str) {
        return Arrays.stream(str).anyMatch(s -> s.matches("^(?:(?:\\+|00)86)?1(?:(?:3[\\d])|(?:4[5-7|9])|(?:5[0-3|5-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\\d])|(?:9[1|8|9]))\\d{8}$"));

    }

    public static boolean isChinaIdCodeLegal(String... str) {
        return Arrays.stream(str).anyMatch(s -> s.matches("(^\\d{8}(0\\d|10|11|12)([0-2]\\d|30|31)\\d{3}$)|(^\\d{6}(18|19|20)\\d{2}(0\\d|10|11|12)([0-2]\\d|30|31)\\d{3}(\\d|X|x)$)"));
    }
    public static boolean isEmailLegal(String...str){
        return Arrays.stream(str).anyMatch(s -> (s.matches("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$")));
    }
}
